﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace DataModel
{
    public enum PhoneType { Private, PrivateMobile, Office, Other };

    public class Phone
    {
        [Column("ID")]
        public int ID { get; set; }
        [Column("PHONETYPE")]
        public int PhoneTypeID { get; set; }
        [Column("NUMBER")]
        public string Number { get; set; }

        public PhoneType PhoneType
        {
            get { return (PhoneType)PhoneTypeID; }
            set { PhoneTypeID = (int)value; }
        }

        public virtual List<Person> Persons { get; set; } 
    }

    public class PhoneConfiguration : EntityTypeConfiguration<Phone>
    {
        public PhoneConfiguration()
        {
            HasKey(x => x.ID);
            Property(x => x.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(x => x.Number).IsRequired();
            HasMany(x => x.Persons);
            ToTable("PHONE");
        }
    }
}
